{layout name="layout1" /}
<style>
    .layui-table-cell {
        height:auto;
    }
    .goods-content>div:not(:last-of-type) {
        border-bottom:1px solid #DCDCDC;
    }
    .goods-data::after{
        display: block;
        content: '';
        clear: both;
    }
    .goods_name_hide{
        overflow:hidden;
        white-space:nowrap;
        text-overflow: ellipsis;
    }
    .operation-btn {
        margin: 5px;
    }
    .table-operate{
        text-align: left;
        font-size:14px;
        padding:0 5px;
        height:auto;
        overflow:visible;
        text-overflow:inherit;
        white-space:normal;
        word-break: break-all;
    }
    .table-count{
        /*border:1px solid red;*/
        text-align: left;
        font-size:14px;
        padding:0 5px;
        height:auto;
        overflow:visible;
        text-overflow:inherit;
        white-space:normal;
        word-break: break-all;
    }
    .table-count  span{
        /*border:1px solid #e8e8e8;*/
        display: inline-block;
        padding:5px 5px;
        margin-right:10px;
        /*border: 1px solid #C9C9C9;*/
        background-color: #fff;
        color: #555;
    }
</style>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
        <div class="layui-collapse like-layui-collapse" lay-accordion="" style="border:1px dashed #c4c4c4">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title like-layui-colla-title" style="background-color: #fff">操作提示</h2>
                <div class="layui-colla-content layui-show">
                    <p>*下单列表，查询订单。</p>
<!--                    <p>*订单状态有待付款，待发货，待收货，已完成，已关闭。</p>-->
<!--                    <p>*待付款订单取消后则为已关闭。待付款订单支付后则为待发货。待发货订单发货后则为待收货。待收货订单收货后则为已完成。</p>-->
                </div>
            </div>
        </div>
        </div>
        <div class="layui-tab layui-tab-card" lay-filter="tab-all">

            <ul class="layui-tab-title">
                <li data-type='' class="layui-this">全部</li>
                {foreach $order_status as $item => $val}
                <li data-type="{$item}">{$val}</li>
                {/foreach}
            </ul>

            <div class="layui-tab-item layui-show">
                <div class="layui-card">
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-row">
                                <div class="layui-inline">
                                    <label class="layui-form-label">订单搜索:</label>
                                    <div class="layui-input-block">
                                        <select name="search_key">
                                            <option value="order_sn">订单编号</option>
                                            <option value="new_bottle_num">订单类型</option>
                                            <option value="site_id">站点ID</option>
                                            <option value="mobile">下单账号</option>
                                            <option value="mobile">配送人ID</option>
<!--                                            <option value="consignee">收货人姓名</option>-->
<!--                                            <option value="consignee_mobile">收货人手机号码</option>-->
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <input type="text" name="keyword" id="keyword" placeholder="请输入搜索内容"
                                           autocomplete="off" class="layui-input">
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">商品名称:</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="goods_name" id="goods_name" placeholder="请输入商品名称"
                                               autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">订单来源:</label>
                                    <div class="layui-input-block">
                                        <select name="order_source" id="order_source">
                                            <option value="">全部</option>
                                            {foreach $order_source as $item => $val}
                                            <option value="{$item}">{$val}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">下单时间:</label>
                                    <div class="layui-input-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" name="start_time" value="{$start_time}" class="layui-input" id="start_time"
                                                   placeholder="" autocomplete="off">
                                        </div>
                                    </div>
                                    <div class="layui-input-inline" style="margin-right: 5px;width: 20px;">
                                        <label class="layui-form-mid">至</label>
                                    </div>
                                    <div class="layui-input-inline">
                                        <input type="text" name="end_time" value="{$end_time}" class="layui-input" id="end_time"
                                               placeholder="" autocomplete="off">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <button class="layui-btn layui-btn-sm layuiadmin-btn-ad {$view_theme_color}" lay-submit
                                            lay-filter="order-search">查询
                                    </button>
                                    <button class="layui-btn layui-btn-sm layuiadmin-btn-ad layui-btn-primary " lay-submit
                                            lay-filter="order-clear-search">清空查询
                                    </button>
                                    <button class="layui-btn layui-btn-sm layuiadmin-btn-ad layui-btn-primary " lay-submit
                                            lay-filter="export-file">导出
                                    </button>
<!--                                    <button class="layui-btn layui-btn-normal layui-btn-sm operation-btn" lay-submit-->
<!--                                            lay-filter="delivery">用户下单-->
<!--                                    </button>-->
                                </div>
                            </div>

                            <div class="layui-row">
<!--                                <div class="layui-inline">-->
<!--                                    <label class="layui-form-label">订单类型:</label>-->
<!--                                    <div class="layui-input-block">-->
<!--                                        <select name="order_type" id="order_type">-->
<!--                                            <option value="">全部</option>-->
<!--                                            {foreach $order_type as $item => $val}-->
<!--                                            <option value="{$item}">{$val}</option>-->
<!--                                            {/foreach}-->
<!--                                        </select>-->
<!--                                    </div>-->
<!--                                </div>-->



<!--                                <div class="layui-inline">-->
<!--                                    <label class="layui-form-label">付款方式:</label>-->
<!--                                    <div class="layui-input-block">-->
<!--                                        <select name="pay_way" id="pay_way">-->
<!--                                            <option value="">全部</option>-->
<!--                                            {foreach $pay_way as $item => $val}-->
<!--                                            <option value="{$item}">{$val}</option>-->
<!--                                            {/foreach}-->
<!--                                        </select>-->
<!--                                    </div>-->
<!--                                </div>-->

                            </div>

                            <div class="layui-row">

<!--                                <div class="layui-inline">-->
<!--                                    <label class="layui-form-label">配送方式:</label>-->
<!--                                    <div class="layui-input-block">-->
<!--                                        <select name="delivery_type" id="delivery_type">-->
<!--                                            <option value="">全部</option>-->
<!--                                            {foreach $delivery_type as $item => $val}-->
<!--                                            <option value="{$item}">{$val}</option>-->
<!--                                            {/foreach}-->
<!--                                        </select>-->
<!--                                    </div>-->
<!--                                </div>-->


                            </div>
                        </div>
                    </div>

                    <div class="layui-card-body">
                        <!--tabel 统计-->
                        <div class="table-count">
                             <span >订气数量(<b class="bottle_num"></b>)<span>
                             <span>商品价格(<b class="bottle_amount"></b>)</span>
                             <span>商品增购金额(<b class="bottle_zenggou"></b>)</span>
                             <span>共享瓶押金(<b class="bottle_deposit"></b>)</span>
                             <span>共享瓶租金(<b class="settle_bottle_rent"></b>)</span>
                             <span>上楼费(<b class="floor_amount"></b>)</span>
                             <span>订单总金额(<b class="order_amount"></b>)</span>
                        </div>
                        <table id="order-lists" lay-filter="order-lists"></table>

                        <script type="text/html" id="order-operation" >
                            <div class="table-operate">
<!--                                <a class="layui-btn layui-btn-normal layui-btn-sm operation-btn" lay-event="delivery">用户下单</a>-->
<!--                                <a class="layui-btn layui-btn-primary layui-btn-sm operation-btn" lay-event="detail">订单详情</a>-->
<!--                                <a class="layui-btn layui-btn-danger layui-btn-sm operation-btn" lay-event="cancel">取消订单</a>-->

                                <a class="layui-btn layui-btn-primary layui-btn-sm operation-btn" lay-event="detail">订单详情</a>
                                {{#  if(d.order_status == '待完成'){ }}
                                <a class="layui-btn layui-btn-danger layui-btn-sm operation-btn" lay-event="cancel">退款</a>
<!--                                <a class="layui-btn layui-btn-normal layui-btn-sm operation-btn" lay-event="delivery">发货</a>-->
                                {{#  } }}

<!--                                {{#  if(d.order_status == 2){ }}-->
<!--                                <a class="layui-btn layui-btn-primary layui-btn-sm operation-btn" lay-event="express">物流查询</a>-->
<!--                                <a class="layui-btn layui-btn-normal layui-btn-sm operation-btn" lay-event="confirm">确认收货</a>-->
<!--                                {{#  } }}-->

<!--                                {{#  if(d.order_status == 3){ }}-->
<!--                                <a class="layui-btn layui-btn-primary layui-btn-sm operation-btn" lay-event="express">物流查询</a>-->
<!--                                {{#  } }}-->

<!--                                {{#  if(d.order_status == 4){ }}-->
<!--                                <a class="layui-btn layui-btn-danger layui-btn-sm operation-btn" lay-event="del">删除订单</a>-->
<!--                                {{#  } }}-->
<!--                                <a class="layui-btn layui-btn-normal layui-btn-sm operation-btn" lay-event="print">小票打印</a>-->
                                <a class="layui-btn layui-btn-normal layui-btn-sm operation-btn" lay-event="remarks">备注</a>

                            </div>
                        </script>

                        <script type="text/html" id="image">
                            <img src="{{d.image}}" style="height:80px;width: 80px" class="image-show">
                        </script>

                        <script type="text/html" id="new_bottle_num">
                            {{#  if(d.order_status == 0){ }}
                            置换
                            {{#  }else{ }}
                            新增
                            {{#  } }}
                        </script>

                        <!--订单信息-->
                        <script type="text/html" id="order">
                            <div style="text-align: left">
                                <p>订单编号:{{d.order_sn}}</p>
                                <p>下单时间:{{d.create_time}}</p>
                                <p>支付时间:{{d.pay_time}}</p>
                                <p>订单来源:{{d.order_source}}</p>
                                <p>留言:{{d.user_remark}}</p>
                            </div>
                        </script>

                        <!--会员信息-->
<!--                        <script type="text/html" id="user">-->
<!--                            <div class="layui-input-inline"  style="text-align: left;">-->
<!--                                <p>会员编号:{{d.user_id}}</p>-->
<!--                                <p style="width: 180px;text-overflow:ellipsis;overflow: hidden">会员昵称:{{d.mobile}}</p>-->
<!--                                <p>会员等级:{{d.user_level}}</p>-->
<!--                            </div>-->
<!--                        </script>-->

                        <!--收货信息-->
                        <script type="text/html" id="delivery">
                            <div style="text-align: left">
                                <p>收货人:{{d.consignee}}</p>
                                <p>手机号码:{{d.mobile}}</p>
                                <p>收货地址:{{d.address}}</p>
                                <p>详细地址门牌号:{{d.address_detail}}</p>

                            </div>
                        </script>

                        <!--金额信息-->
                        <script type="text/html" id="amount">
                            <div style="text-align: left">
                                <p>钢瓶押金:{{d.bottle_deposit}}</p>
                                <p>押瓶租金:{{d.settle_bottle_rent}}</p>
                                <p>上楼费:{{d.floor_amount}}</p>
                                <p>商品价格:{{d.bottle_amount}}</p>
                                <p>订单总金额:{{d.order_amount}}</p>
                                <p>支付方式:{{d.pay_way}}</p>
                            </div>
                        </script>

                        <!--商品信息-->
                        <script type="text/html" id="goods">
                            <div class="goods-content">
                                {{#  layui.each(d.goods_id, function(index, item){ }}
<!--                                    <img src="{{ item.goods_image }}" style="height:80px;width: 80px" class="image-show layui-col-md4">-->
                                        <span class="">{{ item.goods_name }} &nbsp;￥{{ item.goods_price }}&nbsp;x&nbsp;{{ item.goods_number }},</span>
                                {{#  }); }}
                            </div>
                        </script>



                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.config({
        version:"{$front_version}",
        base: '/static/plug/layui-admin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'like', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , like = layui.like
            , element = layui.element
            , laydate = layui.laydate;
        var listType = '';

        //图片放大
        $(document).on('click', '.image-show', function () {
            var src = $(this).attr('src');
            like.showImg(src,600);
        });

        //监听搜索
        form.on('submit(order-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('order-lists', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });
        //清空查询
        form.on('submit(order-clear-search)', function () {
            $('#keyword').val('');
            $('#order_status').val('');
            $('#goods_name').val('');
            $('#pay_way').val('');
            $('#order_type').val('');
            $('#order_source').val('');
            $('#start_time').val('');
            $('#end_time').val('');
            $('#delivery_type').val('');
            form.render('select');
            //刷新列表
            var field = data.field;

            table.reload('order-lists', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });
        //用户下单
        form.on('submit(delivery)', function(data){
            var field = data.field;
            console.log(field)
            layer.open({
                type: 2
                ,title: '用户下单'
                ,content: '{:url("order/delivery")}'
                ,area: ['90%', '90%']
                ,yes: function(index, layero){
                }
            })
        });
        // 导出
        form.on('submit(export-file)', function(data){
            var field = data.field;
            $.ajax({
                url: '{:url("order/exportFile")}?type=' + listType,
                type: 'get',
                data: field,
                dataType: 'json',
                error: function() {
                    layer.msg('导出超时，请稍后再试!');
                },
                success: function(res) {
                    table.exportFile(res.data.exportTitle,res.data.exportData, res.data.exportExt, res.data.exportName);
                },
                timeout: 15000
            });
            layer.msg('导出中请耐心等待~');
        });

        //日期时间范围
        laydate.render({
            elem: '#start_time'
            ,type: 'datetime'
            ,trigger: 'click'
        });


        laydate.render({
            elem: '#end_time'
            ,type: 'datetime'
            ,trigger: 'click'
        });

        //获取列表
        getList(listType);
        //切换列表
        element.on('tab(tab-all)', function (data) {
            $('#keyword').val('');
            $('#order_status').val('');
            $('#goods_name').val('');
            $('#pay_way').val('');
            $('#order_type').val('');
            $('#start_time').val('');
            $('#end_time').val('');
            $('#delivery_type').val('');
            form.render('select');
            listType = $(this).attr('data-type');
            getList(listType);
            if (listType !== ''){
                $('.order_status').hide();
            }else {
                $('.order_status').show();
            }
        });

        function getList(type) {
            let start_time=$('#start_time').val();
            let end_time=$('#end_time').val();
            table.render({
                elem: '#order-lists'
                , url: '{:url("order/lists")}?type=' + type + '&start_time=' +start_time+'&end_time='+end_time
                , cols: [[
                      {field:'id',title: 'ID',width:50,align: 'center', sort: true}
                    , {field: 'order_status', title: '订单状态', align: 'center',width:75}
                    , {field: 'create_time', title: '下单时间', align: 'center',width:160}
                    , {field: 'user_mobile', title: '下单账号', align: 'center',width:120}
                    , {field: 'consignee', title: '收货人姓名', align: 'center',width:75}
                    , {field: 'mobile', title: '收货人手机', align: 'center',width:120}
                    , {field: 'address', title: '收货人地址', align: 'center',width:180}
                    , {field: 'site_id', title: '站点ID', align: 'center',width:100}
                    , {field: 'bottle_site_name', title: '配送站点', align: 'center',width:140}
                    , {field: 'admin_id', title: '配送人ID', align: 'center',width:60}
                    , {field: 'dname', title: '配送人', align: 'center',width:75}
                    , {field: 'total_amount', title: '商品信息', align: 'center',templet:'#goods',width:190}
                    , {field: 'bottle_num', title: '订气数量', align: 'center',width:75}
                    , {field: 'bottle_amount', title: '商品价格', align: 'center',width:100}
                    , {field: 'bottle_deposit', title: '共享瓶押金', align: 'center',width:100}
                    , {field: 'settle_bottle_rent', title: '共享瓶租金', align: 'center',width:100}
                    , {field: 'floor_amount', title: '上楼费', align: 'center',width:100}
                    , {field: 'order_amount', title: '订单总金额', align: 'center',width:100}
                    , {field: 'new_bottle_num', title: '订单类型',align: 'center',width:100}
                    , {field: 'order_source', title: '订单来源', align: 'center',width:100}


                    , {field: 'order_sn', title: '订单编号', align: 'center',width:100}
                    , {fixed: 'right', title: '操作', width: 260, align: 'center', toolbar: '#order-operation'}

                ]]
                , page: true
                , text: {none: '暂无数据！'}
                , parseData: function (res) {
                    // 开始赋值
                    $(".bottle_num").html(res.data.tableCount.bottle_num)
                    $(".bottle_amount").html(res.data.tableCount.bottle_amount)
                    $(".bottle_deposit").html(res.data.tableCount.bottle_deposit)
                    $(".settle_bottle_rent").html(res.data.tableCount.settle_bottle_rent)
                    $(".floor_amount").html(res.data.tableCount.floor_amount)
                    $(".order_amount").html(res.data.tableCount.order_amount)
                    $(".bottle_zenggou").html(res.data.tableCount.bottle_zenggou)
                    return {
                        "code": res.code,
                        "msg": res.msg,
                        "count": res.data.count,
                        "data": res.data.lists,
                        "tableCount":res.data.tableCount
                    };
                }
                ,done: function(res, curr, count){
                    // 解决操作栏因为内容过多换行问题
                    $(".layui-table-main tr").each(function (index, val) {
                        $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
                        $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
                    });
                }
            });
        }

        //监听工具条
        table.on('tool(order-lists)', function (obj) {
            var id = obj.data.id;
            if(obj.event === 'detail'){
                layer.open({
                    type: 2
                    ,title: '订单详情'
                    ,content: '{:url("order/detail")}?id='+id
                    ,area: ['90%', '90%']
                    ,yes: function(index, layero){
                        table.reload('order-lists');
                    }
                })
            }

            //删除订单
            if(obj.event === 'del'){
                layer.confirm('删除后订单将消失，确认删除订单吗?', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    like.ajax({
                        url: '{:url("order/del")}'
                        , data: {'order_id': id}
                        , type: 'post'
                        , success: function (res) {
                            if (res.code == 1) {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                },function () {
                                    table.reload('order-lists');
                                });
                            }
                        },
                    });
                });
            }

            //取消订单
            if(obj.event === 'cancel'){
                layer.confirm('确定退款该订单吗?', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    like.ajax({
                        url: '{:url("order/cancel")}'
                        , data: {'order_id': id}
                        , type: 'post'
                        , success: function (res) {
                            if (res.code == 1) {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                },function () {
                                    table.reload('order-lists');
                                });
                            }
                        },
                    });
                });
            }

            //发货
            if(obj.event === 'delivery'){
                layer.open({
                    type: 2
                    ,title: '用户下单'
                    ,content: '{:url("order/delivery")}?id='+id
                    ,area: ['90%', '90%']
                    ,yes: function(index, layero){

                    }
                })
            }

            //物流信息
            if(obj.event === 'express'){
                layer.open({
                    type: 2
                    ,title: '订单发货'
                    ,content: '{:url("order/express")}?id='+id
                    ,area: ['90%', '90%']
                    ,yes: function(index, layero){

                    }
                })
            }


            //确认收货
            if(obj.event === 'confirm'){
                layer.confirm('确认订单商品已收货吗?', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    like.ajax({
                        url: '{:url("order/confirm")}'
                        , data: {'order_id': id}
                        , type: 'post'
                        , success: function (res) {
                            if (res.code == 1) {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                },function () {
                                    table.reload('order-lists');
                                });
                            }
                        },
                    });
                });
            }

            //商家备注
            if(obj.event === 'remarks') {

                like.ajax({
                    url: '{:url("order/remarks")}'
                    , data: {'id': id}
                    , type: 'get'
                    , success: function (res) {
                        if (res.code === 1) {
                            layer.prompt({title: '备注信息', formType: 2, value: res.data.order_remarks}, function(value, index){
                                layer.close(index);
                                like.ajax({
                                    url: '{:url("order/remarks")}'
                                    , data: {'id': id, "order_remarks": value }
                                    , type: 'post'
                                    , success: function (res) {
                                        if (res.code === 1) {
                                            layui.layer.msg(res.msg, {
                                                offset: '15px'
                                                , icon: 1
                                                , time: 1000
                                            });
                                        }
                                    }
                                });

                            });
                        }
                    }
                });

            }


            if(obj.event ==='print'){
                layer.confirm('确定要打印订单吗？', function(index){
                    like.ajax({
                        url:'{:url("order/orderPrint")}',
                        data:{id:id},
                        type:"post",
                        success:function(res)
                        {
                            if(res.code == 1)
                            {
                                layui.layer.msg(res.msg, {
                                    offset: '15px'
                                    , icon: 1
                                    , time: 1000
                                });
                                layer.close(index); //关闭弹层
                                table.reload('printer-lists'); //数据刷新
                            }
                        }
                    });
                    layer.close(index);
                })

            }
        });
    });
</script>